;(function(){
	var myZoom = function(){
		var img;
		var showDiv;
		
		var overHandler = function(){
			var imgPos = getAbsPos(img);
			showDiv.style.left = imgPos.x+img.offsetWidth+"px";
			showDiv.style.top = imgPos.y+"px";
			showDiv.style.display="block";
			
		}
		var outHandler = function(){
			showDiv.style.display="none";
		}
		var moveHandler = function(event){
			//console.log(event.offsetX);//
			//获得鼠标在小图片上的位置
			var oX = parseInt(event.offsetX);
			var oY = parseInt(event.offsetY);
			//换算到大图片的位置
			var bX = oX*4;
			var bY = oY*4;
			//计算背景图片左上角的位置
			var iX = bX-200;
			var iY = bY-100;
			//修改背景位置
			if((oX>=50 && oY>=25)&&(oX<=150 && oY<=75)){
				showDiv.style.backgroundPositionX=0-iX+"px";
				showDiv.style.backgroundPositionY=0-iY+"px";
			}
			
		}
		
		var getAbsPos = function(ele){
			var el = ele;
			var pos={x:0,y:0};
			
			while(el.offsetParent){
				pos.x += parseInt(el.offsetLeft);
				pos.y += parseInt(el.offsetTop);
				el = el.offsetParent;
			}
			return pos;
		}
		
		var getCss = function(ele,style){
			if(window.getComputedStyle){
				return getComputedStyle(ele)[style];			
			}
			return ele.currentStyle[style];
		}
		var loadEvent = function(){
			img.onmouseover = overHandler;
			img.onmouseout= outHandler;
			img.onmousemove =  moveHandler;
		}
		
		return {
			init:function(){
				img = document.getElementById("mimg");
				showDiv = document.getElementById("zoom");
				loadEvent();
			}
		}
	}();
	myZoom.init();
})();
